home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 …ember: Reference Library / Dev.CD Dec 94.toast / Technical Documentation / Mac Tech Notes (DocViewer) / TE • Text / TE08 Safe cdevs / TE08 Safe cdevs
Encoding:
Text File  |  1994-10-19  |  13.4 KB  |  70 lines  |  [ONLN/HLX2]

  1. TE 8 - Safe cdevs
  2. Text        
  3. Written by:    John Harvey    August 1989
  4. This Technical Note describes a potential problem with Control Panel devices (cdevs) that contain EditText fields and presents a way to avoid it.
  5. The Control Panel chapter in Inside Macintosh, Volume 5 describes, in detail, how run-time errors are handled by the Control Panel and a cdev.  There is, however, a potential problem with cdevs that contain EditText items that this chapter does not cover.
  6. When a cdev is called by the Control Panel, the cdev’s 'DITL' resource is concatenated to the Control Panel’s 'DITL'.  The Control Panel then lets the Dialog Manager update the window.  If the cdev contains an item of type EditText, the Dialog Manager allocates and activates a TEHandle to be used for displaying and editing text.  All of this action happens before the cdev gets the initDev message from the Control Panel.
  7. As detailed in The Control Panel chapter, if an error occurs from which a cdev cannot recover, the cdev should dispose of any private memory and return the appropriate error code or a NIL value to the Control Panel.  The Control Panel then grays out the cdev’s area, displays the appropriate error dialog, and then deletes the items that were added to its 'DITL'.
  8. All of this is fine, except that the TEHandle does not get deallocated.  The EditText items get thrown away, including the strings in the item list that the Dialog Manager would use to store text entered into the EditText field, but the TEHandle stays there and stays active.  Figure 1 illustrates what this would look like.
  9. Figure 1–Erroneous Insertion Point
  10. So the Dialog Manager, knowing that it allocated a TEHandle for an item that was visible, goes merrily on its way flashing the insertion point.  The problem is not simply one of appearance.  If a user hits a key, the Dialog Manager tries to process the key-down event just as if the EditText item was still available, and this series of events causes a rather nasty crash.
  11. Fortunately, the solution for this problem is a very simple one.  If an EditText item is hidden with a _HideDItem call, the Dialog Manager does not consider it active and will not try to process key-down events for it.  So if your cdev contains EditText items, part of your error handling should be to first hide the EditText items with a call to _HideDItem before returning an error code or a NIL as the cdev’s function result.
  12. Further Reference:
  13. •    Inside Macintosh, Volume I, The Dialog Manager
  14. •    Inside Macintosh, Volume IV, The Dialog Manager
  15. •    Inside Macintosh, Volume V, The Control Panel
  16. àHRˇ ˇˇˇˇRH
  17. IR æXæ,Times
  18. .(÷ZTE 8 - Safe cdevs(÷1) of 2(ÏZText°d WORDS †å°d WORDR…†Ç
  19. /ZÅ#
  20.     0Ià:µú9"{    ˇˇˇˇˇˇˇˇ#†ƒ°d
  21. ONLNf˛†å°d1drw2…-·_ġˇˇˇˇˇè°ñ x°ddrw2:°ddrw2:$°d4drw2:°öˇ˙ó@†ò
  22. .WIQkWIQk(B]New Technical Notes†ô°ddrw2:°„†ó°d1drw2eÙġˇˇˇˇˇP°ñ x°ddrw2:°ddrw2:$°d4drw2:°öˇ˚ÄE¿†ò
  23. Ä({ïDeveloper Support†ô°ddrw2:°„†ó°d`drw2-ÔˇˇˇˇˇˇKÔ- Z  ffZ°d1drw2 ¿˙ÈˇˇˇˇˇˇK°ñ x°ddrw2:°ddrw2:$°d4drw2:0°öˇÙĆò
  24. 0(UÔ†ô°ddrw2:°„†ó°d1drw2ÔÊ˙ˇˇˇˇˇˇ°ñ x°ddrw2:°ddrw2:$°d4drw2:    °öˇ˝Ä†ò
  25.     l+&    ®†ô°ddrw2:°„†ó°d1drw2Â-¯yˇˇˇˇˇˇ°ñ x°ddrw2:°ddrw2:$°d4drw2:°öˇ˚Ä%†ò
  26. BÄ(Z\    Macintosh†ô°ddrw2:°„†ó†ç°ddrw2D†É°dWORD†ç
  27. IR.°dONLNdéZ°Ì(úZTE 8 - Safe cdevs
  28. °dONLNd†ZØx*Text
  29. °dONLNdªZ«è* Written by:°dONLNd%ª¢«fl)H John Harvey°dONLNd1ªfl«(ƒfl August 1989°dONLNd=”Zflô(‹Z?This Technical Note describes a potential problem with Control °dONLNd|”ôfl(‹ôPanel devices (cdevs) that°dONLNdó‡ZÏ(ÈZcontain ,
  30. Courier°dONLNdüflÎ∑)%EditText°dONLNd߇∑Ïg)8' fields and presents a way to avoid it. ¯X¯°dONLNdœZÈ(ZThe Control Panel chapter in °dONLNdÏÈ;)èInside Macintosh°dONLNd¸;™)R, Volume 5 describes, °dONLNd™)oin detail, how run-time°dONLNd*Zå(Z?errors are handled by the Control Panel and a cdev.  There is, °dONLNdiå(åhowever, a potential problem°dONLNdÜZ*…('Zwith cdevs that contain °dONLNdû…))oEditText°dONLNd¶*∂)8( items that this chapter does not cover.°dONLNdœ7ZC^(@Z7When a cdev is called by the Control Panel, the cdev’s °dONLNd6^Bà(@^'DITL'°dONLNd 7àC¡)*
  31.  resource is °dONLNd7¡C)9concatenated to the°dONLNd-DZPß(MZControl Panel’s °dONLNd=CßO—)M'DITL'°dONLNdCD—Pfl)*9.  The Control Panel then lets the Dialog Manager update °dONLNd|DflP(Mfl the window.°dONLNdâQZ]v(ZZIf the °dONLNdêQv])cdev contains an item of type °dONLNdÆP\@)íEditText°dONLNd∂Q@])8., the Dialog Manager allocates and activates a°dONLNdÂ]Zií(gZTEHandle°dONLNdÌ^íjû)8: to be used for displaying and editing text.  All of this °dONLNd'^ûj(gûaction happens before the°dONLNdAkZwö(tZcdev gets the °dONLNdOjövÀ)@initDev°dONLNdVkÀwi)1  message from the Control Panel.°dONLNdwÉZès(åZ=As detailed in The Control Panel chapter, if an error occurs °dONLNd¥Ésè(ås!from which a cdev cannot recover,°dONLNd÷êZúP(ôZ2the cdev should dispose of any private memory and °dONLNdêPú)ˆ'return the appropriate error code or a °dONLNd/èõ)∑NIL°dONLNd3úZ®‰(•Zvalue to the Control Panel.  °dONLNdPú‰®)ä>The Control Panel then grays out the cdev’s area, displays the°dONLNdè©Zµ≤(≤ZLappropriate error dialog, and then deletes the items that were added to its °dONLNd€®≤¥‹(≤≤'DITL'°dONLNd·©‹µ‡)*.°dONLNd„¬ZŒˆ(ÀZ%All of this is fine, except that the °dONLNd¡ˆÕ.)úTEHandle°dONLNd¬.Œ«)8  does not get deallocated.  The °dONLNd0¡«Õˇ)ôEditText°dONLNd8¬ˇŒ)8 items°dONLNd?ŒZ⁄â(◊ZAget thrown away, including the strings in the item list that the °dONLNdÄŒâ⁄(◊âDialog Manager would use to°dONLNdú€ZÁÿ(‰Zstore text entered into the °dONLNd∏⁄ÿÊ)~EditText°dONLNd¿€ÁV)8 field, but the °dONLNd–⁄VÊé)FTEHandle°dONLNdÿ€éÁÆ)8 stays °dONLNdfl€ÆÁ) there and stays active.°dONLNd¯ÁZÛ1(Z/Figure 1 illustrates what this would look like.ˇ°¿Ù%%DSIDICT:_cv
  32. currentdict /bu known {bu}if
  33. userdict /_cv known not{userdict /_cv 30 dict put}if
  34. _cv begin
  35. /bdf{bind def}bind def
  36. currentscreen/cs exch def/ca exch def/cf exch def
  37. /setcmykcolor where{/setcmykcolor get /cvcmyk exch def}{/cvcmyk{1 sub 4 1 roll 3{3 index add neg dup 0 lt{pop 0}if 3 1 roll}repeat setrgbcolor pop}bdf }ifelse
  38. /ss{//cf //ca //cs setscreen}bdf
  39. /stg{ss setgray}bdf
  40. /strgb{ss setrgbcolor}bdf
  41. /stcmyk{ss cvcmyk}bdf
  42. /min1{dup 0 eq{pop 1}if}bdf
  43. end
  44. currentdict /bn known {bn}if
  45. †øÚHRˇ ˇˇˇˇRH
  46. IR,Times
  47. .+6-Macintosh Technical Notes /4/˘ æ4æ˘(÷62) of 2(÷≤TE 8 - Safe cdevs+4Text†Ç†å
  48. <V˛ÿ
  49. 4wY˙õò*J|ŒƒJŒ¬wY˚ú⁄ˇ¸ê⁄
  50. ô–⁄
  51. ôp⁄
  52. ôÔ˛ˆˇ¿ˆÙˇÏêı
  53. <0¿Û
  54. ôˈˇ ¿b0`ÙˇÔˇı
  55. `<|y≥Δc«√ΔÛ Ëˆˇ¿`ff1Δfd˛fÙˇÏpı
  56. `ff1Üf√ÊffÛfóˈˇ ¿`ff1ÜffgÊÙˇÓfpı
  57. `ff1ÜfffÛ
  58. ôˈˇ ¿bff1Üfff&ÙˇÏpı
  59. <<fÉΔÊcΔÛ3˜Ô˛ˆˇ¿ˆÙˇÏÃ⁄ ⁄ 0⁄3Ÿˇ3⁄ˇ˝ô
  60. ˘Â
  61. ˘Â@\
  62. ÿ˘(ÂT
  63. ¯˘DÂ
  64. ˘ÇÂ
  65. ˘    Â@\
  66. 8˘
  67. òÂ
  68. x˘É‹Â
  69. ˘Ç ˇˇÇÂ@\ òÇ ˛Âà ˇà ¯ÄHÂ@_w x™®Hˇ¯Â ÄHˇ¸Â ™ÄH 8¡ ¯ÄH 8Â@]/ ®H 8 ¯ÄH <¡ ò®H 8Âf xÄH 8Â@]ô ™H 8 ¯ÄH <Âà ¯ÄH 8Âà ¯ˇà 8Â@\  8 ÿ <Âà x 8Â3 x 8Â@]ô àˇ¯Â òàúÂô ÿ
  70. "8Âô ¯àòÂ@\ 
  71. "8 òˇˇàúÂô 8
  72. "8Â xàòÂ@]ô 
  73. "8 xˇˇàúÂf
  74. ò˘
  75. "8Âf
  76. ¯˘àòÂ@\
  77. ˘
  78. "8Âx8˛¿àúÂfD˛@
  79. "8¡ x@Œ2Ã@àòÂ@]ô M)K@
  80. "8Â 8EÈz@àúÂ3 xE    B@
  81. "8Â3 ¯8…2@àòÂ@\
  82. ˘
  83. "8Â
  84. 8˘àúÂ
  85. ¯˘
  86. "8ÂÃ
  87. x˘àòÂ@]ô
  88. ˘
  89. "8Â
  90. ˘àúÂ
  91. 8˘
  92. "8Â
  93. ¯˘àòÂ@\
  94. ˘
  95. "8ÂX˘àú$Ëÿ˘
  96. "8 ËU˘àò@@`Ë@\˘
  97. "8 Ë˘àú$˪∏˘
  98. "8 ËDX˘àò@@`Ë@\˘
  99. "8 Ëx˘àú$Ëô˛
  100. ˇÄ
  101. "8 Ë¯˛
  102. ``àò@@`Ë@_ˇò˛
  103. Ä
  104. "8 Ëf¯àú$ËŃ
  105. "8 Ë¯
  106. Ç$àò@@`Ë@_ˇÇ"
  107. "8 Ëˇ x"àúÂô ¡
  108. "8Â ÿàòÂ@\Ã xÄ
  109. "8Â3 ¯&¡¯àú $CÑ
  110. "8Â ÿF√|àòÂ@]ô ¯CÅ    Ä
  111. "8ÂÃx@Ú˛àúÂô@˛
  112. "8Âò@˛àòÂ@]ô8@˛
  113. "8¯G˛àúÂMIJ
  114. "8Â xJÄÄàòÂ@^f ÿMÄÄ
  115. "8Âô xGÄàúÂô @Ä
  116. "8Âx ˛àòÂ@^f ˛
  117. "8¡¯˛àú²
  118. "8Â8˛àòÂ@_3ò`˛
  119. "8Âfx˛ˇÄ˛àúÂô
  120. ˘
  121. "8Â8˘àòÁ@@ ¯˘
  122. "8‰Ã¯¿`˛àú˸      ›
  123. &Xfi
  124. x    )`‡3
  125. x    )@‡ô
  126. ))@fi
  127. ∏Δ&@‡"⁄™ÿ†å††
  128. ˇˇˇˇˇˇˇˇÑ`∫—≈ÿ∫“‘ˇª‘◊ˇº◊ÿˇΩ◊ÿˇæ÷◊ˇ¿—“’÷ˇ¡‘’ˇ¬”‘ˇƒ“”ˇ≈—“ˇˇ"Δ—Ù###˘
  129. †°"ª’)ñ†ç°ñ°öf†ò
  130. ¬ǬǰdONLNdˇˇ(H0This line is a result of _DialogSelect calling 
  131. †ô°öˇ˜f†ò°dONLNdˇˇ* _TEIdle†ô†ó†ç†É
  132. IR°dONLNd
  133. ≤|(≤"Figure 1–Erroneous Insertion Point°dONLNd##6/0(,63So the Dialog Manager, knowing that it allocated a ,
  134. Courier°dONLNdV"0.h)˙TEHandle°dONLNd^#h/~)8 for °dONLNdc#~/¯)an item that was visible,°dONLNd}/6;≤(86goes merrily on its way °dONLNdï/≤;¯)|?flashing the insertion point.  The problem is not simply one of°dONLNd’;6Gû(D6appearance.  If a user °dONLNdÏ;ûG¯)hGhits a key, the Dialog Manager tries to process the key-down event just°dONLNd4H6Ta(Q6
  135. as if the °dONLNd>GaSô)+EditText°dONLNdFHôT·)8 item was still °dONLNdVH·T¯)H:available, and this series of events causes a rather nasty°dONLNdëT6`S(]6crash.°dONLNdòm6yô*HFortunately, the solution for this problem is a very simple one.  If an °dONLNd‡lôx—(vôEditText°dONLNdËm—y÷)8 °dONLNdÈm÷y¯)item is°dONLNdÒz6Üy(É6hidden with a °dONLNdˇyyÖø)C
  136. _HideDItem°dONLNd    zøܬ)F °dONLNd
  137. z¬Ü¯)Acall, the Dialog Manager does not consider it active and will not°dONLNdLá6ìd(ê6Atry to process key-down events for it.  So if your cdev contains °dONLNdçÜdíú(êdEditText°dONLNdïáúì‘)8
  138.  items, part °dONLNd¢á‘ì¯)8of your°dONLNd™î6†˜(ù6+error handling should be to first hide the °dONLNd’ì˜ü/)¡EditText°dONLNd›î/†f)8  items with °dONLNdÈîf†ê)7
  139. a call to °dONLNdÛìêü÷)*
  140. _HideDItem°dONLNd˝î÷†¯)F before°dONLNd°6≠∫(™6returning an error code or a °dONLNd"†∫¨œ)ÑNIL°dONLNd%°œ≠Z) as the cdev’s function result.°dONLNdE—6›†(⁄6Further Reference: ›4›˘°dONLNdXfiHÍL+
  141. •°dONLNdZfiZÍ´)Inside Macintosh°dONLNdjfi´ÍE)Q, Volume I, The Dialog Manager°dONLNdâÍHˆL(ÛH•°dONLNdãÍZˆ´)Inside Macintosh°dONLNdõÍ´ˆM)Q, Volume IV, The Dialog Manager°dONLNdªˆHL(ˇH•°dONLNdΩˆZ´)Inside Macintosh°dONLNdÕˆ´?)Q, Volume V, The Control Panelˇ